home *** CD-ROM | disk | FTP | other *** search
- Path: news1.erols.com!newsmaster@erols.com
- From: Chris Cobb <ccobb@cseg.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Floating Point Error Traping by try and catch:-
- Date: 18 Mar 1996 01:29:18 GMT
- Organization: CSEG, Inc.
- Message-ID: <4iie9e$1pp@news5.erols.com>
- References: <4i836n$2u8@dfw-ixnews5.ix.netcom.com>
- NNTP-Posting-Host: ccobb.erols.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.22KIT (Windows; U; 16bit)
-
- rajash@ix.netcom.com(Rajash Gopalakrishnan ) wrote:
- >Hi Experts!.
- >
- >We were using normal try and catch statements to trap
- >the exceptional errors occured during C++ class operation.
- >We are working on Soaris C++ 4.1 with Toolsh++ classes.
- >
- [stuff deleted]
- >Here what I found is that before catch, arithemetic experssion fault
- >occurs and core is dumping. One method I found is to redirect the
- >signal
- >handler and do a catch but that's a round about method. Can anybody
- >explain how we can handle this situation by try and catch alone. Is
- >there
- >any method to show where error occured and line#.
-
- Well, it seems to me that a floating point error is a hardware trap
- which you may be able to intercept with a signal function (I haven't
- tried to catch one lately). Within your signal function you could
- then perform a throw.
-
- Then only way I can see how you could do this without a signal function
- is to override operator/, but you would have to create your own class
- that could be overriden, such as 'class Long'.
-
- Getting the line number would be tough...once you're in operator /, you
- would not know the line number of your caller.
-
- If you *really* wanted the line number and didn't mind getting hackish
- and obscure, you could define an inline function div(long,long) which
- would divide two longs. However, you also define a second inline
- div(long,long,char*file,int line). Then (and here's the hackish part)
- you define a macro:
-
- #if defined(TRACK_LINE_NUMBERS)
- #define div(l1,l2) div(l1,l2,__FILE__,__LINE__)
- #endif
-
- Then whenever you called div() the current file and line number would be
- passed to it and if a zero denominator was passed, an object containing
- the file and line could be thrown. Viola!
-
- Chris
-
-
-
-
-